package com.jqkb.service;

import android.os.Build;
import android.support.annotation.RequiresApi;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.*;

import java.io.File;
import java.util.ArrayList;

public interface ActionService {

    @POST("action/add.json")
    @Multipart
    Call<ResponseBody> actionAdd(
            @Query("title") String title,
            @Part("content") RequestBody content,
            @Query("location") String location,
            @Query("type") String type,
            @Part MultipartBody.Part[] file,
            @Query("targetId") Long[] targetId
    );


    /*@RequiresApi(api = Build.VERSION_CODES.N)
    default Call<ResponseBody> actionAdd(
            String title,
            String content,
            String location,
            String type,
            File[] files,
            Long[] targetIds
    ) {

        ArrayList<MultipartBody.Part> partsList = new ArrayList<>();
        for (int i = 0; files != null && i < files.length; i++) {
            MediaType contentType = MediaType.parse(("multipart/form-data"));
            File file = files[i];
            RequestBody multipartBody = MultipartBody.create(contentType, file);
            MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), multipartBody);
            partsList.add(part);
        }
        MultipartBody.Part[] parts = partsList.toArray(new MultipartBody.Part[0]);

        return actionAdd(title, content, location, type, parts, targetIds);
    }*/

    /**
     * 转上报，再次上报
     */
    @POST("/action/forward.json")
    @FormUrlEncoded
    Call<ResponseBody> actionForward(
            @Field("actionForwardId") Long actionForwardId,
            @Field("fillContent") String fillContent,
            @Field("targetId") Long[] targetId
    );

    /**
     * 批复
     */
    @POST("/action/backward.json")
    @FormUrlEncoded
    Call<ResponseBody> actionBackward(
            @Field("actionBackwardId") Long actionBackwardId,
            @Field("actionForwardId") Long actionForwardId,
            @Field("fillContent") String fillContent
    );

    /**
     * 已阅归档(信息)
     */
    @POST("/action/readForward.json")
    @FormUrlEncoded
    Call<ResponseBody> readForward(
            @Field("actionForwardId") Long actionForwardId
    );

    /**
     * 已阅归档(批复)
     */
    @POST("/action/readBackward.json")
    @FormUrlEncoded
    Call<ResponseBody> readBackward(
            @Field("actionBackwardId") Long actionBackwardId
    );

    /**
     * 待处理信息
     */
    @POST("/action/forward/list/pending.json")
    @FormUrlEncoded
    Call<ResponseBody> actionForwardListPending(
            @Field("pageSize") int pageSize,
            @Field("pageNumber") int pageNumber
    );

    /**
     * 已处理信息
     */
    @POST("/action/forward/list/processed.json")
    @FormUrlEncoded
    Call<ResponseBody> actionForwardListProcessed(
            @Field("pageSize") int pageSize,
            @Field("pageNumber") int pageNumber,
            @Field("filterType") String filterType
    );

    /**
     * 上级批示
     */
    @POST("/action/backward/list/pending.json")
    @FormUrlEncoded
    Call<ResponseBody> actionBackwardListPending(
            @Field("pageSize") int pageSize,
            @Field("pageNumber") int pageNumber
    );


    /**
     * 办结信息
     */
    @POST("/action/backward/list/processed.json")
    @FormUrlEncoded
    Call<ResponseBody> actionBackwardListProcessed(
            @Field("pageSize") int pageSize,
            @Field("pageNumber") int pageNumber,
            @Field("filterType") String filterType
    );

    /**
     * 信息详细
     */
    @POST("/action/forward/detail.json")
    @FormUrlEncoded
    Call<ResponseBody> actionForwardDetail(
            @Field("actionId") Long actionId,
            @Field("actionForwardId") Long actionForwardId
    );

    /**
     * 批复详细
     */
    @POST("/action/backward/detail.json")
    @FormUrlEncoded
    Call<ResponseBody> actionBackwardDetail(
            @Field("actionId") Long actionId,
            @Field("actionBackwardId") Long actionBackwardId
    );

    /**
     * 信息跟踪
     */
    @GET("/action/forward/history.json")
    @FormUrlEncoded
    Call<ResponseBody> actionForwardHistory(
            @Field("actionForwardId") Long actionForwardId
    );

    /**
     * 新信息监听接口
     * 返回代码非常重要:
     * 2000:有数据
     * 2001:下次请求才能获取数据
     * 1001:需要登录
     * 1003:超时， 一般10分钟
     * 1008:你已有新的监听，你应该停止监听（一个loginKey监听2次前一个会受到1008）
     */
    @POST("/action/listen_new_message.json")
    Call<ResponseBody> listenNewMessage();


}
